package com.m2soft.streaming
{
	import flash.display.Bitmap;
	import flash.display.DisplayObject;
	import flash.events.MouseEvent;
	import flash.filters.DropShadowFilter;
	
	import mx.controls.Image;
	
	public class DupImage extends Image
	{
		private static var m_PageColor : int = 0xffffff;
		private static var m_PageBorderColor : int = 0x000000;

		public function DupImage()
		{
		}
		
		static public function SetPageColor(rgb : uint):void
		{
			m_PageColor = rgb;
		}

		static public function SetPageLineColor(rgb : uint):void
		{
			m_PageBorderColor = rgb;
		}

		override public function set source(value:Object):void{
			if(this.source != null && this.source is Bitmap && this.source.bitmapData != null){
				this.source.bitmapData.dispose();
			}
			
			super.source = value;
			
			if(value!=null){
				if(this.filters.length==0){addDropShadow();}
			}
		}
		
		override protected function createChildren():void {
			super.createChildren();
			
			addEventListener(MouseEvent.ROLL_OVER,dupImageMoverHandler,false,0,true);
		}
		
		private function dupImageMoverHandler(event:MouseEvent):void // depricated.. only used when using bitmaps to render 
		{
		}
				
		public function addDropShadow():void
		{
			return;
			if(this.filters.length==0){
			this.filters = null;
			 var filter : DropShadowFilter = new DropShadowFilter();
			 filter.blurX = 4;
			 filter.blurY = 4;
			 filter.quality = 2;
			 filter.alpha = 0.5;
			 filter.angle = 45;
			 filter.color = 0x202020;
			 filter.distance = 4;
			 filter.inner = false;
			 this.filters = [ filter ];
			}
		}			
		
		public function addGlowFilter():void
		{
			return;
			var filter : flash.filters.GlowFilter = new flash.filters.GlowFilter(0x111111, 1, 5, 5, 2, 1, false, false);
			filters = [ filter ];
		}
		
		
		public function removeAllChildren():void
		{
			while(numChildren > 0)
				delete(removeChildAt(0));
			
			this.filters = null;
		}
		
		override public function addChild(child:DisplayObject):DisplayObject
		{
			//flash.utils.setTimeout(addDropShadow,200);
			super.addChildAt(child,0);
			
			while(numChildren >= 2)
				delete(removeChildAt(1));
			
			return super.getChildAt(0);
		}
		
		override protected function updateDisplayList(w:Number, h:Number):void 
		{
			if(w>0 && h>0)
			{
				try
				{
					graphics.beginFill(m_PageColor, 1);
					graphics.lineStyle(1, m_PageBorderColor);
					graphics.drawRect(0,0,w,h);
					super.updateDisplayList(w,h);
				}
				catch (e:*) {}
			}
		}	 
		
	}
}